var jquery,
    authtree,
    form,
    layer,
    table;

$(document).ready(function(){
    addEvent(document.getElementById('recycleBtn'), 'click', recycleRolesCB);
});

layui.config({
    base: '/static/lib/layuiadmin/',
}).extend({
    authtree: 'modules/authtree',
}).use(['jquery', 'authtree', 'form', 'layer','table'], function(){
    jquery = layui.jquery;
    authtree = layui.authtree;
    form = layui.form;
    layer = layui.layer;
    table = layui.table;

    table.render({
        id: 'idTest'
        , elem: '#test'
        , url: '/sys-duty/page'
        , method: 'post'
        , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        , even: true//隔行变色
        , limits: [10, 20, 30, 50, 80, 100]//每页条数的选择项，默认：[10,20,30,50,80,100]。
        , limit: 10//每页显示的条数（默认：10）
        , height: 400
        , request: {}
        , where: {dutyState: 2}
        , cols: [[
            {type:'checkbox'}
            ,{field: 'id', width: 120, title: 'ID', sort: true, align: 'center'}
            , {field: 'dutyName', title: '角色名称', align: 'left'}
        ]]
        , page: true
    });
});

/*
* @author: wj
* @description: 批量恢复
* @date: 2019/2/16 12:04
* @param
* @return
*/
function recycleRolesCB() {
    var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值

    if (checkStatus.data.length == 0) {
        layer.alert("请选择要恢复的数据！");
        return;
    }

    layer.confirm('确定要恢复吗？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        ActHttpRequest("/sys-duty/recycle", {"dutyList":JSON.stringify(checkStatus.data)}, function (data) {
            if (data.code === 0) {
                layer.msg('恢复成功！', {icon: 1});

                var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(thisindex);
            } else {
                layer.alert(data.message);
            }
        });
    });
}